home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UUPC11QS.ARJ / HOSTATUS.C < prev    next >
C/C++ Source or Header  |  1991-11-17  |  4KB  |  114 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    h o s t a t u s . c                                             */
  3. /*                                                                    */
  4. /*    Load host status information for UUPC/extended                  */
  5. /*                                                                    */
  6. /*    Copyright (c) 1991, Andrew H. Derbyshire                        */
  7. /*--------------------------------------------------------------------*/
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <time.h>
  12.  
  13. #include "lib.h"
  14. #include "hlib.h"
  15. #include "hostable.h"
  16. #include "hostatus.h"
  17. #include "security.h"
  18.  
  19. /*--------------------------------------------------------------------*/
  20. /*        Define current file name for panic() and printerr()         */
  21. /*--------------------------------------------------------------------*/
  22.  
  23. currentfile();
  24.  
  25. /*--------------------------------------------------------------------*/
  26. /*                          Global variables                          */
  27. /*--------------------------------------------------------------------*/
  28.  
  29. time_t start_stats = 0;
  30.  
  31. void HostStatus( void )
  32. {
  33.  
  34.    char fname[FILENAME_MAX];
  35.    char buf[BUFSIZ];
  36.    struct HostTable *host;
  37.    FILE *stream;
  38.    size_t len1;
  39.    size_t len2;
  40.  
  41.    mkfilename( fname, spooldir, DCSTATUS );
  42.  
  43.    if ((stream  = FOPEN(fname , "r", BINARY)) == NULL)
  44.    {
  45.       printmsg(1,"HostStatus: Unable to open host status file");
  46.       time(&start_stats);
  47.       return;
  48.    }
  49.  
  50. /*--------------------------------------------------------------------*/
  51. /*                    Read the header information                     */
  52. /*--------------------------------------------------------------------*/
  53.  
  54.    fread( &len1, sizeof len1, 1, stream );
  55.    fread( &len2, sizeof len2, 1, stream );
  56.    fread( buf , 1, len1, stream);
  57.    buf[len1++] = ' ';
  58.    fread( buf + len1 , 1, len2, stream);
  59.    buf[ len1 + len2 ] = '\0';
  60.    fread( &start_stats , sizeof start_stats , 1,  stream);
  61.    printmsg(5,"HostStatus: %s generated by %s beginning %s", fname, buf ,
  62.          ctime(&start_stats));
  63.  
  64. /*--------------------------------------------------------------------*/
  65. /*                           Load each host                           */
  66. /*--------------------------------------------------------------------*/
  67.  
  68.    while  (!feof( stream ) && !ferror(stream))
  69.    {
  70.       if (fread( &len1, sizeof len1, 1, stream ) < 1)
  71.          break;
  72.       fread( &len2, sizeof len2, 1, stream );
  73.       fread( buf , sizeof host->hostname[0], len1, stream);
  74.       buf[ len1 ] = '\0';
  75.       printmsg(5,"HostStatus: Name length %d, status length %d, \
  76. host name \"%s\"",
  77.             len1, len2, buf );
  78.       host = checkreal( buf );
  79.  
  80.       if ( host == BADHOST )
  81.       {
  82.          printmsg(1,"HostStatus: Host \"%s\" not found, purging entry",
  83.                buf );
  84.          fread( buf , len2, 1,  stream);
  85.       }
  86.       else if ( len2 <= (sizeof *(host->hstats)))
  87.       {
  88.          fread( host->hstats , len2, 1,  stream);
  89.          printmsg(5,"HostStatus: Loaded status for host %s",
  90.                   host->hostname);
  91.          if (( host->hstats->save_hstatus >= nocall ) &&
  92.              ( host->hstats->save_hstatus < last_status ))
  93.             host->hstatus = host->hstats->save_hstatus;
  94.          else
  95.             printmsg(0,"HostStatus: Invalid status (%d) ignored for \"%s\"",
  96.                host->hstats->save_hstatus,host->hostname ) ;
  97.       }
  98.       else {
  99.          printmsg(5,"HostStatus: Bad record length %d (wanted %d), \
  100. purging status for host %s", len2, (int) (sizeof *(host->hstats)), buf);
  101.          fread( buf , len2, 1,  stream);
  102.       } /* else */
  103.    } /* while */
  104.  
  105.    if (ferror( stream ))
  106.    {
  107.       printerr( fname );
  108.       clearerr( stream );
  109.    }
  110.  
  111.    fclose( stream );
  112.  
  113. } /* HostStatus */
  114.